//
//  PaymentPartialView.m
//  ios-supplier
//
//  Created by feynmanyuan on 15/4/19.
//  Copyright (c) 2015年 feynmanyuan. All rights reserved.
//

#import "PaymentPartialView.h"

@interface PaymentPartialView()
@property (weak, nonatomic) IBOutlet UILabel *paymentLabel;
@property (weak, nonatomic) IBOutlet UILabel *paymentExtLabel;
@property (weak, nonatomic) IBOutlet UILabel *paymentTipsLabel;

@end

@implementation PaymentPartialView

- (void)setOrder:(JFBOrderDS*)order{
    
    NSUInteger totalHeight = kOrderCellHeaderHeight * 5 / 4;
    
    CGSize paymentSize = [order.payment sizeWithAttributes:@{NSFontAttributeName: [UIFont systemFontOfSize:TextFontSizeH3]}];
    CGFloat paymentY = (totalHeight - paymentSize.height) / 2;
    CGFloat paymentX = kOrderCellSpacing;
    CGRect paymentRect = CGRectMake(paymentX, paymentY, paymentSize.width, paymentSize.height);
    self.paymentLabel.frame = paymentRect;
    self.paymentLabel.text = order.payment;
    
    NSString *paymentExt;
    NSUInteger pymentExtFontSize = TextFontSizeH3;
    if( (int)order.paymentOrigin == 1 ) {
        paymentExt = @"已线上支付";
        [self.paymentTipsLabel removeFromSuperview];
    } else {
        paymentExt = [NSString stringWithFormat:@"¥ %@", [NSString decimalToString:order.money]];
        pymentExtFontSize = TextFontSizeH2;
        self.paymentExtLabel.textColor = TextColorImportant;
        self.paymentLabel.textColor = TextColorImportant;
        self.paymentExtLabel.font = [UIFont systemFontOfSize:pymentExtFontSize];
    }
    
    CGFloat fixX = 10;
    
    CGSize paymentExtSize = [paymentExt sizeWithAttributes:@{NSFontAttributeName: [UIFont systemFontOfSize:pymentExtFontSize]}];
    CGFloat paymentExtY = (totalHeight - paymentExtSize.height) /2;
    CGFloat paymentExtX = self.bounds.size.width - paymentExtSize.width - kOrderCellSpacing;
    CGRect paymentExtRect = CGRectMake(paymentExtX - fixX, paymentExtY, paymentExtSize.width + fixX, paymentExtSize.height);
    self.paymentExtLabel.font = [UIFont systemFontOfSize:pymentExtFontSize];
    self.paymentExtLabel.text = paymentExt;
    self.paymentExtLabel.frame = paymentExtRect;
    
    if( (int)order.paymentOrigin != 1 ) {
        CGFloat paymentTipsY = paymentY;
        CGFloat paymentTipsX = paymentExtX - kOrderCellSpacing - fixX - self.paymentTipsLabel.bounds.size.width;
        CGRect paymentTipsRect = CGRectMake(paymentTipsX, paymentTipsY, self.paymentTipsLabel.bounds.size.width, self.paymentTipsLabel.bounds.size.height);
        self.paymentTipsLabel.frame = paymentTipsRect;
    }
    
    self.height = totalHeight + 1;
}

@end
